home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / BetterADsecurity.sit / Better AD security / Source / ES Handler.c < prev    next >
C/C++ Source or Header  |  1996-06-21  |  7KB  |  208 lines

  1. /*    NAME:
  2.         ES Handler.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant,
  6.         Avi Drissman
  7.                 
  8.     DESCRIPTION:
  9.         This file contains an ES Handler for use by Extension Shell.
  10.  
  11. This was started 10:15 PM, May 9, 1996
  12.  
  13.     ___________________________________________________________________________
  14. */
  15. //=============================================================================
  16. //        Include files                                                                     
  17. //-----------------------------------------------------------------------------
  18. #include <Gestalt.h>
  19. #include <Traps.h>
  20. #include "A4Stuff.h"
  21. #include "SetupA4.h"
  22. #include "ES.h"
  23. #include "ES Address Table.h"
  24. #include "bADs Constants.h"
  25. #include "ES Handler.h"
  26.  
  27.  
  28. //=============================================================================
  29. //        Private function prototypes                                                                     
  30. //-----------------------------------------------------------------------------
  31. void    main(short theMsg, ESParamBlock *theParamBlock);
  32. void    InitialiseParamBlock(void);
  33. void    InitialiseAddrsTable(void);
  34. void    HandleTheError(void);
  35. void    SetUpIcons(short animDelay, short numIcons, short firstIcon);
  36.  
  37.  
  38. //=============================================================================
  39. //        Global variables                                                                 
  40. //-----------------------------------------------------------------------------
  41. ESParamBlock    *gTheParamBlock;
  42.  
  43.  
  44. //=============================================================================
  45. //        main : Entry point to our code resource.                                                                 
  46. //-----------------------------------------------------------------------------
  47. //        Note :    Extension Shell communicates with us via a message constant,
  48. //                and a pointer to a structure it owns. Our job is to fill in
  49. //                the details in that structure, depending on what it wants us
  50. //                to do.
  51. //-----------------------------------------------------------------------------
  52. void main(short theMsg, ESParamBlock *theParamBlock)
  53. {    long            oldA4;
  54.  
  55.  
  56.  
  57.     // Set up A4 so that we can access our globals
  58. #ifndef powerc
  59.     oldA4 = SetCurrentA4();
  60. #endif
  61.     gTheParamBlock = theParamBlock;
  62.  
  63.  
  64.  
  65.     // Case out on what we have to do
  66.     switch(theMsg) {
  67.         case kInitialiseParamBlock:
  68.              InitialiseParamBlock();
  69.              break;
  70.              
  71.         case kInitialiseAddrsTable:
  72.              InitialiseAddrsTable();
  73.              break;
  74.  
  75.         case kHandleError:
  76.              HandleTheError();
  77.              break;
  78.     
  79.         default:
  80.              ;
  81.     }
  82.  
  83.  
  84.     // Restore A4
  85. #ifndef powerc
  86.     SetA4(oldA4);
  87. #endif
  88. }
  89.  
  90.  
  91. //=============================================================================
  92. //        InitialiseParamBlock : Initialises the ParamBlock.                                                                 
  93. //-----------------------------------------------------------------------------
  94. //        Note :    We have three tasks to perform.
  95. //                    • Check to see if we can run
  96. //                    • Set up the icons we want to display
  97. //                    • Set up the code we want installed
  98. //-----------------------------------------------------------------------------
  99. void InitialiseParamBlock(void)
  100. {
  101.  
  102.     // Check for System 7. We depend on having System 7, and won't
  103.     // run if we don't have it. If we don't have it, we beep, post
  104.     // an error message, and show our disabled icon(s).
  105.     if (gTheParamBlock->systemVersion < 0x0700)
  106.         {
  107.         // Error details
  108.         gTheParamBlock->beepNow                = true;
  109.         gTheParamBlock->postError            = true;
  110.         gTheParamBlock->errorStringsID        = kErrorStrings;
  111.         gTheParamBlock->errorStringIndex    = kNeedSystemSeven;
  112.  
  113.  
  114.         // Icon details
  115.         SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  116.         }
  117.     
  118.     // Otherwise, we're allowed to run. If we had a Control Panel, we
  119.     // would also check to see if our Control Panel had turned us
  120.     // off (by setting some preference resource).
  121.     else
  122.         {
  123.         
  124.         // We install one trap patch, one code block, and request an address table
  125.         gTheParamBlock->installAddressTable        = true;
  126.         gTheParamBlock->addressTableSelector    = kbADsAddressTable;
  127.         gTheParamBlock->numCodeResources        = 1;
  128.  
  129.  
  130.         // Details for a trap patch to SysError
  131.         gTheParamBlock->theCodeResources[kNewSysError].resType    = kSysErrorResType;
  132.         gTheParamBlock->theCodeResources[kNewSysError].resID    = kSysErrorResID;
  133.         gTheParamBlock->theCodeResources[kNewSysError].codeType    = kTrapPatchType;
  134.         gTheParamBlock->theCodeResources[kNewSysError].theCodeThing.theTrapPatch.trapWord = kSysErrorTrap;
  135.         gTheParamBlock->theCodeResources[kNewSysError].theCodeThing.theTrapPatch.globalpatch = true;
  136.         
  137.         }
  138. }
  139.  
  140.  
  141. //=============================================================================
  142. //        InitialiseAddrsTable : Initialise the address table.                                                     
  143. //-----------------------------------------------------------------------------
  144. //        Note :    If we requested an address table, Extension Shell calls us back
  145. //                to allow us to initialise any extensions we've made to it.
  146. //
  147. //                This routine will only be called if we request an address
  148. //                table, and is called after the address table is installed,
  149. //                but before any of the items in gTheParamBlock->theCodeResources
  150. //                are processed (since they might need to access the address
  151. //                table).
  152. //-----------------------------------------------------------------------------
  153. void InitialiseAddrsTable(void)
  154. {
  155.  
  156. // Nothin' here
  157.  
  158. }
  159.  
  160.  
  161.  
  162. //=============================================================================
  163. //        HandleTheError : Handle any errors                                                             
  164. //-----------------------------------------------------------------------------
  165. //        Note :    This routine is called if an error occurred during the
  166. //                installation of the items in gTheParamBlock->theCodeResources.
  167. //
  168. //                If an error occurs we beep, post an error, and request that
  169. //                as much as possible of our code be uninstalled. We also reset
  170. //                the icon details to show our disabled icons.
  171. //-----------------------------------------------------------------------------
  172. void HandleTheError(void)
  173. {
  174.  
  175.  
  176.     // Decide how we want to handle the error
  177.     gTheParamBlock->removeInstalledCode    = true;
  178.     gTheParamBlock->beepNow                = true;
  179.     gTheParamBlock->postError            = true;
  180.     gTheParamBlock->errorStringsID        = kErrorStrings;
  181.  
  182.  
  183.     // Message to display to the user
  184.     gTheParamBlock->errorStringIndex = kUnknownError;
  185.  
  186.  
  187.     // Icon details
  188.     SetUpIcons(kDisabledAnimDelay, kMyNumDisabledIcons, kMyFirstDisabledIcon);
  189. }
  190.  
  191.  
  192. //=============================================================================
  193. //        SetUpIcons : Set up our the icon fields in gTheParamBlock.                                                         
  194. //-----------------------------------------------------------------------------
  195. //        Note :    We are passed in the resource ID of the first icon, the number
  196. //                of icons, and a delay for animation. We fill these details
  197. //                in to gTheParamBlock.
  198. //-----------------------------------------------------------------------------
  199. void SetUpIcons(short animDelay, short numIcons, short firstIcon)
  200. {    short        i;
  201.  
  202.  
  203.     gTheParamBlock->animationDelay    = animDelay;
  204.     gTheParamBlock->numIcons        = numIcons;
  205.     for (i = 1; i <= numIcons; i++)
  206.         gTheParamBlock->theIcons[i] = firstIcon + i - 1;
  207. }
  208.